package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;

    /**
     * 查
     * @return
     */
    @GetMapping
    public List<User> findAll(){
        return userService.findAll();
    }

    /*
    * 增加
    * */
    @PostMapping
    public boolean add(@RequestBody User user){
        userService.add(user);
        return true;
    }

    /*
    * 删除
    * */
    @DeleteMapping("{id}")
    public boolean delete(@PathVariable("id")Integer id){
       userService.deleteById(id);
       return true;
    }    /*
    * 修改
    * */
    @PutMapping
    public void update(@RequestBody User user){
        userService.updateUser(user);
    }

    /*
    * 条件查询
    * */
    @GetMapping("query")
    public List<User> queryByPage(
            @RequestParam("current")Integer current,
            @RequestParam("size")Integer size,
            @RequestParam("condition") String condition
            ){
        return userService.queryByPage(current,size,condition);
    }



}
